package com.atguigu.realtime.gmallpublisher2.service;

import com.atguigu.realtime.gmallpublisher2.mapper.TMMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author lzc
 * @Date 2020/11/24 16:40
 */
@Service
public class PublisherServiceImp implements PublisherService {

    @Autowired
    TMMapper mapper;

    @Override
    public Map<String, BigDecimal> getTMAmountSum(String start, String end, int limit) {
        List<Map<String, Object>> tmAmountSumList = mapper.getTMAmountSum(start, end, limit);

        Map<String, BigDecimal> result = new HashMap<>();
        for (Map<String, Object> map : tmAmountSumList) {
            String tm_name = map.get("tm_name").toString();
            BigDecimal amount = (BigDecimal) map.get("amount");
            result.put(tm_name, amount);
        }

        return result;
    }
}
